package ee.difference.beans;

import java.beans.PropertyDescriptor;

import ee.difference.principal.DiffEntry;

public class PropertyDescriptorEntry implements DiffEntry<PropertyDescriptorEntry> {

	private String key;
	
	public PropertyDescriptor entry;
	
	public PropertyDescriptorEntry(PropertyDescriptor desc){
		this.entry = desc;
		this.key = desc.getName();
	}
	
	/* (non-Javadoc)
	 * @see ee.difference.DiffEntry#compareTo(ee.difference.PropertyDescriptorEntry)
	 */
	public int compareTo(PropertyDescriptorEntry o) {
		return this.key.compareTo(o.getKey().toString());
	}
	
	/* (non-Javadoc)
	 * @see ee.difference.DiffEntry#getKey()
	 */
	public String getKey(){
		return key;
	}
	
	/* (non-Javadoc)
	 * @see ee.difference.DiffEntry#getEntry()
	 */
	public PropertyDescriptor getEntry(){
		return this.entry;
	}
	
	/* (non-Javadoc)
	 * @see ee.difference.DiffEntry#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		
		if(obj == null )
			return false;
		
		if(!obj.getClass().equals(this.getClass()))
			return false;
		
		return (this.hashCode() == obj.hashCode());
	}
	
	@Override
	public String toString() {
		return PropertyDescriptorEntry.class.getName() + ":" + key;
	}
	
	@Override
	public int hashCode() {
		return this.toString().hashCode();
	}

}
